<?php
class Building_model extends CI_Model {
	
	private $tbl_data= 'MST_BUILDING';
	public function __construct()
	{
		parent::__construct();
	}
	
	function list_all(){
		//$this->db->order_by('id','asc');
		return "SELECT * FROM MST_BUILDING";
	}
	
	function get_all(){
                $sql="SELECT * FROM MST_BUILDING ORDER BY BDNAME";
		return $this->db->query($sql)->result_array();;
	}
	function get_building_tou($fccode)
        {
                     $sql=" SELECT A.BDCODE,B.BDNAME FROM dbo.MST_METER_MASTER  A
                             INNER JOIN dbo.MST_BUILDING B ON A.BDCODE=B.BDCODE
                             WHERE A.FCCODE='$fccode' AND A.STCODE in (1,89,90)
                             GROUP BY  A.BDCODE,B.BDNAME ";
            
             return $this->db->query($sql)->result_array();
        }
	function count_all(){
		return $this->db->count_all($this->tbl_data);
	}
	
	function get_by_id($id){
		$this->db->where('BDCODE', $id);
		return $this->db->get($this->tbl_data)->row();
	 
	}
	function get_by_name($id){
		$this->db->where('BDNAME', $id);
		return $this->db->get($this->tbl_data)->row();
	 
	}
	function save($item){		
		$this->db->insert($this->tbl_data, $item);
                return $this->db->insert_id();
	}
	
	function update($item,$id){
		$this->db->where('BDCODE', $id);
		$this->db->update($this->tbl_data, $item);
	}
	
	function delete($id){
		$this->db->where('BDCODE', $id);
		$this->db->delete($this->tbl_data);
	}
}
?>